axios.defaults.baseURL = '../login/';
axios.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded';
axios.defaults.transformRequest =function (data) {
    let transObj='';
    for(let i in data){
        transObj+=i+'='+data[i]+'&';
    }
    return transObj;
}

const vm = new Vue({
    el:'#dv',
    data:{
        name: '',
        password: '',
        passwordAgain: '',
    },
    methods:{
        register(){
            if(this.password!==this.passwordAgain){
                this.password = this.passwordAgain =''
                return alert('密码不相同')
            }
            axios.post('add.php',
                {name: this.name,
                 password: this.password})
                .then(result => {
                    if (result.status === 200) {
                        if(result.data.code==200){
                            location.href='sign.html'
                        }
                    } else {
                        alert(result.data.msg)
                    }
                })
        }
    }
})

